import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class test4 {
    public static void main(String[] args) {
        FileReader fileReader = null;
        try {
            File file = new File("test.txt");
            fileReader = new FileReader(file);
            int read = fileReader.read();
            System.out.println((char) read);
        } catch (IOException e) {
            System.out.println("读取文件时出错: " + e.getMessage());
        } finally {
            // 在finally块中确保资源被关闭
            if (fileReader != null) {
                try {
                    fileReader.close();
                    System.out.println("文件流已关闭");
                } catch (IOException e) {
                    System.out.println("关闭文件流时出错: " + e.getMessage());
                }
            }
        }
    }
}